<?php

namespace app\admin\controller;

use utils\Date\Date;

class Index extends Admin {

    public function index() {

        $admin = admin_is_login();

        $this->assign('admin', $admin);

        return view();
    }

    public function home() {

        if (empty($_GET['timea']))
            $_GET['timea'] = date('Y-m-d', time() - 86400 * 30);
        if (empty($_GET['timeb']))
            $_GET['timeb'] = date('Y-m-d');


        $day = Date::date_diff('d', $_GET['timea'], $_GET['timeb']) + 1;


        // 帖子30天内增长
        $lists = model('thread')->model_where()->chart((Date::date_diff('d', $_GET['timea'], $_GET['timeb']) + 1));
        $this->assign('lists', $lists);


        // 用户30天内增长           
        $lists2 = model('member')->model_where()->chart((Date::date_diff('d', $_GET['timea'], $_GET['timeb']) + 1));
        $this->assign('lists2', $lists2);

        // 磁盘使用率
        $df = @disk_free_space(".") / (1024 * 1024 * 1024);
        $dt = @disk_total_space(".") / (1024 * 1024 * 1024);

        $disk_per = round((1 - $df / $dt) * 100, 0);

        $this->assign('disk_per', $disk_per);


        // 统计
        $count_thread = model('thread')->count();
        $count_thread_reply = model('thread_comment')->count();
        $count_member = model('member')->count();

        // 附件大小及数量 
        $res_size = dir_size(APP_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . APP_THEME);
        $res_number = dir_number(APP_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . APP_THEME);
        
        // 美化
        $res_size = format_bytes($res_size);

        $this->assign(compact('count_thread', 'count_thread_reply', 'count_member', 'res_size', 'res_number'));

        return view();
    }

}
